package com.qcit.common.activity
import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.qcit.common.R

open class BaseFragment : Fragment() {

    fun toast(toast: String) {
        Toast.makeText(context, toast, Toast.LENGTH_SHORT).show()
    }

    fun toastNetError() {
        Toast.makeText(context, getText(R.string.err_network), Toast.LENGTH_SHORT).show()
    }

    fun showLoading(show: Boolean) {
        try {
            val activity = activity as BaseActivity
            activity.showLoading(show)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    fun startActivity(clazz: Any) {
        startActivity(Intent(activity, clazz::class.java))
    }


    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (!hidden)
            onResume()
    }
}